package controller

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type JsonStruct struct {
	Code  int `json:"code"`
	Msg   any `json:"msg"`
	Data  any `json:"data,omitempty"` // omitempty: 如果 Data 为空，则不返回该字段
	Count int `json:"count,omitempty"`
}

func ReturnSuccess(c *gin.Context, code int, msg any, data any, count int) {
	json := &JsonStruct{Code: code, Msg: msg.(string), Data: data, Count: count}
	c.JSON(http.StatusOK, json)
}

func ReturnError(c *gin.Context, code int, msg any) {
	json := &JsonStruct{Code: code, Msg: msg.(string)}
	c.JSON(http.StatusOK, json)
}
